import request from "@/utils/request";

// 数据表中的列表
export function getDatabeseList(query) {
    return request({
        url: `/system/table/${query.dirId}/list`,
        method: "get",
        params: query
    });
}
// 数据表中全部表
export function getDatabeseAllList(query) {
    return request({
        url: `/system/table/${query.dirId}/allTable`,
        method: "get",
        params: query
    });
}
// /system/table/{dirId}/tableMap
export function getTableMapList(query) {
    var dirId = query.dirId;
    var params = query;
    if (query.tableId) {
        delete params.dirId;
    }
    return request({
        url: `/system/table/${dirId}/tableMap`,
        method: "get",
        params: params
    });
}

// 表的基础信息
export function getDataBeseBasic(query) {
    return request({
        url: "/system/table/" + query.tableId + "/metadata",
        method: query.methods || "get",
        data: query.data
    });
}

// 表单详情-数据预览
export function getDateViewList(query) {
    return request({
        url: `/system/table/${query.tableId}/data`,
        method: "get",
        params: query
    });
}
export function dataDaturability (query){
  return request({
    url: `/system/table/${query.tableId}/dataDaturability`,
    method: 'get',
    params:query,
  })
};
// 表单详情- 编辑和新增数据预览
export function addAndEditDateViewList(query) {
    return request({
        url: `/system/table/${query.tableId}/data`,
        method: query.method || "put",
        data: query.data
    });
}

// 表单详情-元数据信息-基础信息
export function getFieldsList(query) {
    console.log(query);
    var tableId = query.params.tableId;
    return request({
        url: `/system/table/${tableId}/metadata/fields`,
        method: "get",
        params: query.params
    });
}
// 表单详情-元数据信息-修改基础信息
export function setFieldsList(query) {
    return request({
        url: `/system/table/${query.tableId}/metadata/fields`,
        method: query.method || "put",
        data: query.data
    });
}

export function deletemetadata (query){
  return request({
    url: `system/table/${query.dirId}/metadata/relation/delete?relationId=`+query.relationId,
    method: "delete",
  })
};
// /datacenter/system/table/{relationId}/metadata/relation/delete?dirId=

//表单详情-元数据信息-变更记录
export function getlogList(query) {
    return request({
        url: `/system/log/list`,
        method: query.method || "get",
        params: query
    });
}

// 表单详情-元数据信息-关联关系
export function getRelationList(query) {
    return request({
        url: `/system/table/${query.tableId}/metadata/relation`,
        method: "get",
        params: query
    });
}
// 表单详情-元数据信息-编辑关联关系
export function EditRelationList(query) {
    return request({
        url: `/system/table/${query.tableId}/metadata/relation`,
        method: query.method || "post",
        data: { list: query.list }
    });
}

/**
 * /system/apply  权限申请
 * V1.0 接口，V1.1 废弃
 * @param {*} data
 * @returns
 */
// export function postApply (data){
//   return request({
//     url: `/system/apply`,
//     method: "post",
//     data: data
//   })
// };

/**
 * /system/apply/submitApply  权限审批--提交申请
 * V1.1 新接口，system/apply 不再使用
 * @param {Object} data
 * @returns
 */
export function postApply(data) {
    return request({
        url: `/system/apply/submitApply`,
        method: "post",
        data: data
    });
}

// 创建表
export function createTable(data) {
    return request({
        url: `/system/table/${data.dirId}/ddl/create`,
        method: "post",
        data: data
    });
}
// 检测新建字段
export function sqlVerify(data) {
    return request({
        url: `/system/table/${data.dirId}/ddl/create/sqlVerify`,
        method: "post",
        data: data
    });
}
// 复制表
export function copyTable(data) {
    return request({
        url: `/system/table/${data.dirId}/ddl/copy`,
        method: "post",
        data: data
    });
}

// 血缘关系
export function LineageList(query) {
    return request({
        url: `/system/table/${query.tableId}/lineage`,
        method: "get",
        params: query.data
    });
}
// 数据预览 导出按钮
export function dateViewExport(query) {
    console.log(query);
    var tableId = query.tableId;
    return request({
        url: `/system/table/${tableId}/export`,
        method: "get",
        params: query.query,
        timeout: 300000 // 单独设置 5 分钟超时
    });
}

// 按表名
export function searchTableList(query) {
    return request({
        url: `/system/table/list`,
        method: "get",
        params: query
    });
}

/*
 * 数据库管理模块接口
 */

// 修改数据目录表字段状态
export function editDataFieldStatus(data) {
    return request({
        url: `/system/table/editDataFieldStatus`,
        method: "post",
        data
    });
}

// 修改数据目录状态
export function editDataTreeStatus(data) {
    return request({
        url: `/system/table/editDataTreeStatus`,
        method: "post",
        data
    });
}

// 根据tableId获取表字段信息
export function getDataTreeByTableId(params) {
    return request({
        url: `/system/table/getDataTreeByTableId`,
        method: "get",
        params
    });
}

// 获取数据目录列表
export function getDataTreeList(params) {
    return request({
        url: `/system/table/getDataTreeList`,
        method: "get",
        params
    });
}
// 按字段名
export function searchFieldsList(query) {
    return request({
        url: `/system/table/field/list`,
        method: "get",
        params: query
    });
}
